// ==UserScript==
// @name         etode相关开发1
// @namespace    http://tampermonkey.net/
// @version      2.0
// @description  try to take over the world!
// @author       You
// @match        https://www.e-cology.com.cn/*
// @icon         
// @grant        none
// ==/UserScript==

(function () {

	window.hideMenu = function () {
		let len = jQuery(".side-menu-item-span").length
		for (let i = 0; i < len; i++) {
			let name = jQuery(jQuery(".side-menu-item-span")[i]).html()

			if (name == '我的团队任务' || name == '公共收藏' || name == '客户') {
				jQuery(jQuery(".side-menu-item-span")[i]).parent("li").hide()
			} else if (name == '回归测试' || name == '报表') {
				jQuery(jQuery(".side-menu-item-span")[i]).parent().parent().hide()
			}
		}

		let len2 = jQuery(".nav-menu-item").length
		for (let i = 0; i < len2; i++) {
			let name = jQuery(jQuery(".nav-menu-item")[i]).html()
			if (name == '需求管理') {
				jQuery(jQuery(".nav-menu-item")[i]).hide()

			}
		}
	}

	window.demo = function () {
		let id = jQuery(".wea-todo-taskview-content-task-id").html().split('#')[1];
		window.open('https://www.e-cology.com.cn/wui/etodo.html#/taskpack/autoPackage?taskId=' + id);
	}

	/**
	 * 获取标红文件列表
	 */
	window.redMouseover = function () {
		try {
			window.svnlist = [];
			jQuery.find("font[color='#ff0000'").map((span) => { svnlist.push(span.innerText) })
			jQuery.find("span[color='#ff0000'").map((span) => { svnlist.push(span.innerText) })
			jQuery("p[style='font-size:15px; text-align:left; font-family:Calibri,sans-serif']").find("span[style='font-size:14px; font-family:\"Arial\",\"sans-serif\"; color:red']").map(
				(p, element) => {
					var a = element.innerText;
					svnlist.push(jQuery(element).parent()[0].innerText);
				}
			)

		} catch (error) {
			antd.message.error('获取标红文件列表失败！');
		} finally {
			if(svnlist.length==0)
			antd.message.error('此qc无标红文件');
		}

	}

	/**
	 * 后端交互渲染dialog
	 */
	window.checkOut = function () {
		// 任务title信息
		try {
			var taskinfo = jQuery(".wea-todo-taskview-content-task-titlecopy")[0].dataset.clipboardText.substring(1)
		} catch (e) {
			antd.message.error('获取任务title信息失败');
			throw e;
		}

		//标准文件地址信息
		var standardinfo = "";
		try {
			try {
				standardinfo = jQuery("span[style='font-size:10pt']")[jQuery("span[style='font-size:10pt']").length - 1].innerText
			}
			catch (e) {
				standardinfo = jQuery("p[style='font-size:15px; text-align:left; font-family:Calibri,sans-serif']")[jQuery("p[style='font-size:15px; text-align:left; font-family:Calibri,sans-serif']").length - 1].innerText
			}
		} catch (e) {
			antd.message.error('获取标准文件失败');
			//throw e;
		}

      //回调地狱可以用promise+aysnc awite解决 但是我不会
     //获取客户基本信息
		jQuery.ajax({
			type: "post",
			url: "https://www.e-cology.com.cn/customersystem/update/AutoPackOperation.jsp",//请求地址
			// 标红文件列表,任务title信息,标准文件信息
			data: { operation: 'getPackInfo', qcNum: taskinfo.split('\n')[0] },
			success: function (packInfo) {
                   jQuery.ajax({
                    type: "post",
                    url: "https://www.e-cology.com.cn/customersystem/update/CustomerEnvironmentOperation.jsp",//请求地址
                    // 标红文件列表,任务title信息,标准文件信息
                    data: { customerId:JSON.parse(packInfo).customerId, operation: 'getCusInfo'},
                    success: function (customInfo) {
                        //渲染dialog
                        jQuery.ajax({
                            type: "post",
                            url: "http://localhost:4396/jsp/tempdata.jsp",//请求地址
                            // 标红文件列表,任务title信息,标准文件信息
                            data: { svnlist: svnlist.join(","), taskinfo: taskinfo, standardinfo: standardinfo,packInfo:packInfo,customInfo:customInfo,customerId:JSON.parse(packInfo).customerId},
                            async: false,
                            success: function (msg) {
                                antd.message.success("预保存标红文件列表成功");

			        window.open("http://localhost:4396/jsp/test.jsp?customerId="+JSON.parse(packInfo).customerId,"_blank")
				/*
                                ecCom.WeaTools.createDialog({
                                    title: '一键检出',
                                    url: "http://localhost:4396/jsp/test.jsp",
                                    icon: "icon-coms-workflow",
                                    iconBgcolor: "#0079DE",
                                    style:{width:900,height:900},
                                    hasScroll: true,
                                    mask:true,
                                    loading:true,
                                    callback: (datas) => { // 数据通信
                                    },
                                    onCancel: () => { // 关闭通信
                                    },
                                }, null, (dialog) => {
                                    // 由于组件异步化可能导致第一次没有加载到组件，所以需要在回调中调用
                                    dialog.show();
                                });
			       */
                            },
                            error: function (msg) {
                                antd.message.error("预保存标红文件列表失败");
                            }
                        });
                    },
                    error: function (msg) {
                    }
                });
			},
			error: function (msg) {
				antd.message.error(msg);
			}
		});
	}

     window.writeBlog= function () {
        //获取条件;
        //https://www.e-cology.com.cn/api/todo/task/getTaskListForMicroBlog

      var conditions="[{\"queryKey\":\"id\",\"queryRpd\":\"\",\"queryValue\":\"\"},{\"queryKey\":\"title\",\"queryRpd\":\"\",\"queryValue\":\"\"},{\"queryKey\":\"stts\",\"queryValue\":\"10,20,30,35,40,50,60,70,80,90\"},{\"queryKey\":\"priority\"},{\"queryKey\":\"create_time\",\"queryValue\":[\"0\"]},{\"queryKey\":\"dev_property\",\"queryValue\":\"10,20,30,35,40,50,60,70,80,90,100,110\"},{\"queryKey\":\"description\",\"queryValue\":\"\"},{\"queryKey\":\"test_plan_finish_date\",\"queryValue\":[\"0\"]},{\"queryKey\":\"test_actual_finish_date\",\"queryValue\":[\"0\"]},{\"queryKey\":\"dev_plan_finish_date\",\"queryValue\":[\"0\"]},{\"queryKey\":\"dev_actual_finish_date\",\"queryValue\":[\"0\"]}]";



       jQuery.ajax({
            type:"POST",
            url:"https://www.e-cology.com.cn/api/todo/task/getTaskListForMicroBlog",
            data : { limit: 30, offset: 0,conditions:conditions },
            async : false,
            dataType: 'json',
            success:function(res){
                var data= res.data_list



        var head="<table border=\"1\" style=\"word-break: break-all\">"
        head+="    <tbody>"
        head+="<tr>"
        head+=" <th style=\"text-align: center;font-size: 16px;background-color: turquoise;color: #4c4949\" width=\"80\">编号</th>"
        head+="<th style=\"text-align: center;font-size: 16px;background-color: turquoise;color: #4c4949\" width=\"100\">优先级</th>"
        head+="<th style=\"text-align: center;font-size: 16px;background-color: turquoise;color: #4c4949\" width=\"100\">开发性质</th>"
        head+="<th style=\"text-align: center;font-size: 16px;background-color: turquoise;color: #4c4949\" width=\"250\">标题</th>"
        head+="<th style=\"text-align: center;font-size: 16px;background-color: turquoise;color: #4c4949\" width=\"100\">状态</th>"
        head+="<th style=\"text-align: center;font-size: 16px;background-color: turquoise;color: #4c4949\" width=\"125\">开发人员</th>"
        head+="<th style=\"text-align: center;font-size: 16px;background-color: turquoise;color: #4c4949\" width=\"125\">创建时间</th>"
        head+="</tr>"

        var body=""

                for(var i=0;i<data.length;i++){


                    body+="<tr>"

                  // console.log( "qc",data[i].task.id+)

                    body+=" <td style=\"font-size: 13px;text-align: center;\">"+data[i].task.id+"</td>"

                  //  console.log( "labelof_priority",data[i].labelof_priority)
                    body+=" <td style=\"font-size: 13px;text-align: center;\">"+data[i].labelof_priority+"</td>"

                    //console.log( "labelof_dev_property",data[i].labelof_dev_property)
                     body+=" <td style=\"font-size: 13px;text-align: center;\">"+data[i].labelof_dev_property+"</td>"

                    // console.log( "labelof_dev_property",data[i].task.title)
                    body+=" <td style=\"font-size: 13px;text-align: center;\">"+data[i].task.title+"</td>"
                   //  console.log( "labelof_stts",data[i].labelof_stts)
                      body+=" <td style=\"font-size: 13px;text-align: center;\">"+data[i].labelof_stts+"</td>"

                    // console.log( "dev_usernames",data[i].task.dev_usernames)
                    body+=" <td style=\"font-size: 13px;text-align: center;\">"+data[i].task.dev_usernames+"</td>"

                   // console.log( "labelof_create_time",data[i].labelof_create_time)
                    body+=" <td style=\"font-size: 13px;text-align: center;\">"+data[i].labelof_create_time+"</td>"

                   body+="</tr>"

                }
                 body+="</tbody>"
                 body+="</table>"

         //发布
         jQuery.ajax({
            type:"POST",

            url:"https://www.e-cology.com.cn/api/blog/base/saveOrUpdateBlog",
            data : { workdate:"", content: head+body ,appItemId:'1',comefrom:'0',shareType:'1',shareValue:'',atChooseId:'',fromTag:'2',hideContent:'hideContent',dbCheck:'0'},
            async : false,
            dataType: 'json',
            success:function(res){
               alert("提交成功")

            } ,

             error: function(xhr){
                console.log(xhr,'加载失败');
            }

        });
           console.log(head+body)

            } ,error: function(xhr){
                console.log(xhr,'加载失败');
            }

        });

       }



	window.setInterval(function () {

		//隐藏菜单
		hideMenu()

		//添加一键检出按钮。
		if (jQuery("button[id='btn2']").length == 0) {
			jQuery(".wea-todo-taskview-content-task-modify-title").prepend("<button type='button' class='ant-btn ant-btn-primary btn-modify-submit' onClick = 'window.checkOut()' onmouseover='window.redMouseover()'  id='btn2'><span>检出</span></button>");

		}
		//添加自动打包按钮。
		if (jQuery("button[ecid^='undefined_Button@wdd2n9_button@xq1ea3']").length == 0) {
			jQuery(".title-btns").append('<button ecid="undefined_Button@wdd2n9_button@xq1ea3"  type="button" class="ant-btn ant-btn-primary" onClick = "window.demo()"  style="border-radius: 3px 0px 0px 3px;"><span>自动打包</span></button>')
		}
     
      //写微博
      if(new Date().getHours()>=17&&new Date().getMinutes()>30){
		if(jQuery("#xieweibo").length<1){

			jQuery(".ant-col-10").prepend("<button type='button' id='xieweibo' class='ant-btn ant-btn-primary btn-modify-submit' onClick = 'window.writeBlog()' ><span>写微博</span></button>")
		}
      }
    




   


	}, 100);


})();
